package com.ketai.web;

import com.ketai.common.MessageConstant;
import com.ketai.service.StyleService;
import com.ketai.service.impl.StyleServiceImpl;
import com.ketai.util.Pages;
import com.ketai.util.SendUtil;
import com.ketai.vo.StyleVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @Author:长沙科泰梦想学院-蓝色小药丸
 * @Mission:打造演说·创客型跨境电商与互联网人才
 * @Description: 研学风采图片路径处理
 * @Date:Create In 2022/8/10 22:53
 **/
@WebServlet("/admin/styleManger")
public class StyleImageServlet extends HttpServlet {

    StyleService service = new StyleServiceImpl();

    @Override
    protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String opr = req.getParameter("opr");

        if ("save".equals(opr)) {
            String id = req.getParameter("id");
            String[] imgPath = req.getParameterValues("imgurl[]");
            // 后期从session中获取
            String uid = "1";
            service.saveStyle(id, Arrays.toString(imgPath), uid);
            SendUtil.Sendjson(resp, "风采照片提交成功！");

        } else if ("list".equals(opr)) {
            String title = req.getParameter("title");
            String checked = req.getParameter("checked");
            String curr = req.getParameter("page");
            String limit = req.getParameter("limit");
            Pages pages = service.getStyleList(title, checked, curr, limit);
            //调用工具类 返回数据给前端
            SendUtil.SendPageJson(resp, pages);
        } else if ("check".equals(opr)) {
            String id = req.getParameter("id");
            String open = req.getParameter("open");
            String desc = req.getParameter("desc");
            //审核人信息  后续从session中获取
            String pid = "1";
            int result = service.checkedActity(id, open, desc, pid);
            if (result > 0) {
                SendUtil.Sendjson(resp, MessageConstant.STYLE_CHECK_SUCCESS);
            } else {
                SendUtil.Sendjson(resp, MessageConstant.STYLE_CHECK_ERROR);
            }


        }


    }
}
